package com.xc58.highreactor.serialize;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import com.xc58.highreactor.compress.GZIPCompress;
import com.xc58.highreactor.seril.ArrayListSerializer;
import com.xc58.highreactor.seril.ArraySerializer;
import com.xc58.highreactor.seril.LinkedListSerializer;
import com.xc58.highreactor.seril.SerialMatcher;

public class Main {
	public static void main(String[] args) throws Exception {
		TestEntity entity = new TestEntity(null, 11, null, '中','国',(short)21, (short)22, 31L, 32L,"123123");
		TestEntity newObj = new TestEntity();
		
		TestEntity test111 = new TestEntity("8888", 111, 112, '呗','嚄',(short)221, (short)222, 331L, 332L,"9999");
		entity.setEntity(test111);
		
		entity.setOarray1(new Object[]{null,1,3,test111});
		
		entity.setIarray(new int[]{3,5,33});
		
		ArrayList list = new ArrayList();
		list.add(1);
		list.add(null);
		list.add("23123");
		
		
		LinkedList  linked = new LinkedList();
		linked.add("1");
		linked.add(null);
		linked.add(3);
		
		System.out.println(Arrays.toString(new LinkedListSerializer().serialize(linked)));
		System.out.println(new LinkedListSerializer().deserialize(new ByteArrayInputStream(new LinkedListSerializer().serialize(linked))));
		
		System.out.println(list.size());
		
		entity.setList(list);
		
		System.out.println(Arrays.toString(new ArrayListSerializer().serialize(list)));
		
		System.out.println(Arrays.toString(new ArraySerializer().serialize(new int[]{3,5,33})));
		
		GZIPCompress compress = new GZIPCompress();
		byte[] inner = compress.compress(SerialMatcher.serializer(entity));
		
		System.out.println(inner.length);
		
		inner = compress.decompress(inner);
		System.out.println(inner.length);
		ByteArrayInputStream input = new ByteArrayInputStream(inner);
		System.out.println(SerialMatcher.deserializer(input));
	}

	public <T> T getTest(T t){
		return t;
	}
}
